<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>添加申报用户</title>
<link rel="stylesheet" type="text/css" href="../css/blueprint/screen.css" media="screen, projection"/>
<link type="text/css" href="../css/redmond/jquery-ui-1.7.custom.css" rel="stylesheet" />
<script type="text/javascript" src="../script/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="../script/jquery-ui-1.7.custom.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
	$(".date-text").datepicker( { dateFormat: 'yy-mm-dd', changeYear: true, changeMonth: true, dayNamesMin: ['日', '一', '二', '三', '四', '五', '六'], monthNamesShort: ['1','2','3','4','5','6','7','8','9','10','11','12']} );
    prepare();
    $("#CREATEUSER_BUTTON").click(createUser);
    $("#SUBMIT_BUTTON").click(modifyUnit);
});
function prepare() {
    $.getJSON("AddUnitPrepareInit.action",
        function(data) {
        
            var provinceArr = new Array();
            for (var i = 0; i < data.provinceList.length; i++) {
                provinceArr.push('<option value="' + data.provinceList[i].pid + '">' + data.provinceList[i].name + '</option>');
            }
            $("#unit_province_code").append(provinceArr.join(''));
            
            var qualificationArr = new Array();
            for (var j = 0; j < data.qualificationList.length; j++) {
                qualificationArr.push('<option value="' + data.qualificationList[j].qualificationCode + '">' + data.qualificationList[j].qualificationName + '</option>');
            }
            $("#user_qualification_code").append(qualificationArr.join(''));
            
            var titleArr = new Array();
            for (var k = 0; k < data.titleList.length; k++) {
                titleArr.push('<option value="' + data.titleList[k].titleCode + '">' + data.titleList[k].titleName + '</option>');
            }
            $("#user_title_code").append(titleArr.join(''));

            var unitkindArr = new Array();
            for (var l = 0; l < data.unitkindList.length; l++) {
            	unitkindArr.push('<option value="' + data.unitkindList[l].kindCode + '">' + data.unitkindList[l].kindName + '</option>');
            }
            $("#unit_kind_code").append(unitkindArr.join(''));

            var credentialArr = new Array();
            for (var m = 0; m < data.credentialList.length; m++) {
            	credentialArr.push('<option value="' + data.credentialList[m].credentialCode + '">' + data.credentialList[m].credentialName + '</option>');
            }
            $("#user_credential_code").append(credentialArr.join(''));

            $("#unit_province_code").change(function() {
                if ($(this).val() != '' && $(this).val() != null) {
                    $.getJSON("AddUnitPrepareCity.action", {"provinceId": $(this).val()},
                        function(data) {
                            var cityArr = new Array();
                            for (var l = 0; l < data.cityList.length; l++) {
                                cityArr.push('<option value="' + data.cityList[l].id + '">' + data.cityList[l].name + '</option>');
                            }
                            $("#unit_city_code").empty().append(cityArr.join(''));
                        }
                    );
                }
            });

            prepareUnit();
        }
    );
}
function prepareUnit() {
	$.ajax({
        type: "post",
        url:  "PrepareEditUnit.action",
        dataType: "json",
        success:  function(data) {
        	$("#unit_name").val(data.unit.unitName);
            $("#unit_e_name").val(data.unit.unitEName);
            $("#unit_abbreviation").val(data.unit.unitAbbreviation);
            $("#unit_address").val(data.unit.unitAddress);
            $("#unit_homepage").val(data.unit.unitHomepage);
            $("#unit_legal_person").val(data.unit.unitLegalPerson);
            $("#unit_province_code").val(data.unit.unitProvinceCode);
            $.getJSON("AddUnitPrepareCity.action", {"provinceId": data.unit.unitProvinceCode},
                function(data) {
                    var cityArr = new Array();
                    for (var l = 0; l < data.cityList.length; l++) {
                        cityArr.push('<option value="' + data.cityList[l].id + '">' + data.cityList[l].name + '</option>');
                    }
                    $("#unit_city_code").empty().append(cityArr.join(''));
                    $("#unit_city_code").val(data.unit.unitCityCode);
                }
            );
            $("#unit_kind_code").val(data.unit.unitKindCode);
            $("#unit_phone").val(data.unit.unitPhone);
            $("#unit_fax").val(data.unit.unitFax);
            $("#unit_email").val(data.unit.unitEmail);
            $("#unit_postcode").val(data.unit.unitPostcode);
            $("#unit_org_code1").val(data.unit.unitOrgCode1);
            $("#unit_org_code2").val(data.unit.unitOrgCode2);
            $("#contact_name").val(data.unit.contactName);
            $("#contact_phone").val(data.unit.contactPhone);
            $("#contact_mobile").val(data.unit.contactMobile);
            $("#contact_fax").val(data.unit.contactFax);
            $("#contact_email").val(data.unit.contactEmail);
            $("#user_id").val(data.unit.userId);
            $("#user_name").val(data.unit.userName);
            $("#user_sex").val(data.unit.userSex);
            $("#user_birthday").val(data.unit.userBirthday);
            $("#user_email").val(data.unit.userEmail);
            $("#user_credential_code").val(data.unit.userCredentialCode);
            $("#user_credential_no").val(data.unit.userCredentialNo);
            $("#user_title_code").val(data.unit.userTitleCode);
            $("#user_position").val(data.unit.userPosition);
            $("#user_department").val(data.unit.userDepartment);
            $("#user_qualification_code").val(data.unit.userQualificationCode);
            $("#user_profession").val(data.unit.userProfession);
            $("#user_phone").val(data.unit.userPhone);
            $("#user_mobile").val(data.unit.userMobile);
            $("#user_address").val(data.unit.userAddress);
            $("#UNITID_HIDDEN").val(data.unit.unitId);
        }
    });
}
function modifyUnit() {
    $.ajax({
        type: "post",
        url:  "ModifyUnit.action",
        data: {
    		"unit.unitId" : $("#UNITID_HIDDEN").val(),
            "unit.unitName": $("#unit_name").val(),
            "unit.unitEName": $("#unit_e_name").val(),
            "unit.unitAbbreviation": $("#unit_abbreviation").val(),
            "unit.unitAddress": $("#unit_address").val(),
            "unit.unitHomepage": $("#unit_homepage").val(),
            "unit.unitLegalPerson": $("#unit_legal_person").val(),
            "unit.unitProvinceCode": $("#unit_province_code").val(),
            "unit.unitCityCode": $("#unit_city_code").val(),
            "unit.unitKindCode": $("#unit_kind_code").val(),
            "unit.unitPhone": $("#unit_phone").val(),
            "unit.unitFax": $("#unit_fax").val(),
            "unit.unitEmail": $("#unit_email").val(),
            "unit.unitPostcode": $("#unit_postcode").val(),
            "unit.unitOrgCode1": $("#unit_org_code1").val(),
            "unit.unitOrgCode2": $("#unit_org_code2").val(),
            "unit.contactName": $("#contact_name").val(),
            "unit.contactPhone": $("#contact_phone").val(),
            "unit.contactMobile": $("#contact_mobile").val(),
            "unit.contactFax": $("#contact_fax").val(),
            "unit.contactEmail": $("#contact_email").val(),
            "unit.userId": $("#user_id").val(),
            "unit.userName": $("#user_name").val(),
            "unit.userSex": $("#user_sex").val(),
            "unit.userBirthday": $("#user_birthday").val(),
            "unit.userEmail": $("#user_email").val(),
            "unit.userCredentialCode": $("#user_credential_code").val(),
            "unit.userCredentialNo": $("#user_credential_no").val(),
            "unit.userTitleCode": $("#user_title_code").val(),
            "unit.userPosition": $("#user_position").val(),
            "unit.userDepartment": $("#user_department").val(),
            "unit.userQualificationCode": $("#user_qualification_code").val(),
            "unit.userProfession": $("#user_profession").val(),
            "unit.userPhone": $("#user_phone").val(),
            "unit.userMobile": $("#user_mobile").val(),
            "unit.userAddress": $("#user_address").val()
        },
        dataType: "json",
        success:  function(data) {
            if (data.status == "success") {
                alert('修改单位操作成功');
                window.location.href = "ManageDeclareUnit.html";
            }
        }
    });
}
function createUser() {
    $.getJSON("CreateUser.action",
        {
            "userId": $("#USERNAME_TEXT").val(),
            "enabled": $("#ENABLED_CHECKBOX").is(":checked") ? "1" : "0"
        },
        function(data) {
            if (data.saveStatus == "success") {
                $("#USERPASSWORD_LABEL").val(data.userPass);
                $("#user_id").val(data.uid);
            } else if (data.saveStatus == "error") {
                alert("生成用户发生错误");
            }
        }
    );
}
</script>
</head>
<body>
<input type="hidden" id="UNITID_HIDDEN"/>
<table align="center" cellpadding="0" cellspacing="0" width="99%">
    <tr>
        <td valign="top" width="100%">
            <table cellspacing="0" cellpadding="0" width="100%">
                <tr>
                    <td valign="top" width="100%">
                        <table align="center" cellpadding="2" cellspacing="0">
                            <tr>
                                <td bgcolor="#dddddd" colspan="4">一、编制单位信息：</td>
                            </tr>
                            <tr>
                                <td width="17%">单位名称：</td>
                                <td align="left" colspan="3"><input type="text" id="unit_name" />*</td>
                            </tr>
                            <tr>
                                <td>英文名称：</td>
                                <td colspan="3"><input type="text" id="unit_e_name"/></td>
                            </tr>
                            <tr>
                                <td>单位简称：</td>
                                <td colspan="3"><input type="text" id="unit_abbreviation" /></td>
                            </tr>
                            <tr>
                                <td>单位地址：</td>
                                <td colspan="3"><input type="text" id="unit_address" />*</td>
                            </tr>
                            <tr>
                                <td>单位主页：</td>
                                <td colspan="3"><input type="text" id="unit_homepage" maxlength="100" /></td>
                            </tr>
                            <tr>
                                <td>法人代表：</td>
                                <td width="46%"><input type="text" id="unit_legal_person" maxlength="10"/>*</td>
                                <td width="13%">单位电话：</td>
                                <td width="24%"><input type="text" id="unit_phone" maxlength="20"/>*</td>
                            </tr>
                            <tr>
                                <td>所在地区：</td>
                                <td><select id="unit_province_code">
                                    <option value="">选择省</option>
                                </select>
                                    <select id="unit_city_code">
                                        <option value="">选择市</option>
                                    </select>*</td>
                                <td>单位传真：</td>
                                <td><input type="text" id="unit_fax" maxlength="20"/>*</td>
                            </tr>
                            <tr>
                                <td>单位性质：</td>
                                <td><select id="unit_kind_code">
                                    <option value="">选择单位性质</option>
                                </select>*</td>
                                <td>电子信箱：</td>
                                <td><input type="text" id="unit_email" maxlength="50"/>*</td>
                            </tr>
                            <tr>
                                <td>组织机构代码：</td>
                                <td><input type="text" id="unit_org_code1" maxlength="10"/> - <input type="text" id="unit_org_code2" size="2" maxlength="1" />*</td>
                                <td>邮政编码：</td>
                                <td><input type="text" id="unit_postcode" maxlength="10" />*</td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td valign="top" width="100%">
                        <table align="center" cellspacing="0" cellpadding="2">
                            <tr>
                                <td bgcolor="#dddddd" colspan="4">二、业务负责人信息：</td>
                            </tr>
                            <tr>
                                <td width="17%">姓名：</td>
                                <td width="46%"><input type="text" id="contact_name" />*</td>
                                <td width="13%">电话：</td>
                                <td width="24%"><input type="text" id="contact_phone" />*</td>
                            </tr>
                            <tr>
                                <td>移动电话：</td>
                                <td><input type="text" id="contact_mobile" /></td>
                                <td>传真：</td>
                                <td><input type="text" id="contact_fax" /></td>
                            </tr>
                            <tr>
                                <td>电子信箱：</td>
                                <td><input type="text" id="contact_email" /></td>
                                <td></td>
                                <td></td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td valign="top" width="100%">
                        <table align="center" cellspacing="0" cellpadding="2">
                            <tr>
                                <td bgcolor="#dddddd" colspan="4">三、注册用户基本信息：</td>
                            </tr>
                            <tr>
                                <td width="17%">用户名：</td>
                                <td width="46%"><input type="text" id="USERNAME_TEXT"/>*<input type="checkbox" id="ENABLED_CHECKBOX"/>(是否启用)<input type="button" id="CREATEUSER_BUTTON" value="创建用户" /><input type="hidden" id="user_id" /></td>
                                <td width="13%">密码：</td>
                                <td width="24%"><input type="text" id="USERPASSWORD_LABEL" readonly="readonly"/></td>
                            </tr>
                            <tr>
                                <td width="17%">姓名：</td>
                                <td width="46%"><input type="text" id="user_name" />*</td>
                                <td width="13%">性别：</td>
                                <td width="24%"><select id="user_sex">
                                        <option value="0" selected="selected">男</option>
                                        <option value="1">女</option>
                                    </select>*</td>
                            </tr>
                            <tr>
                                <td>出生日期：</td>
                                <td><input type="text" id="user_birthday" class="date-text" />*</td>
                                <td>电子信箱：</td>
                                <td><input type="text" id="user_email" />*</td>
                            </tr>
                            <tr>
                                <td>证件类型：</td>
                                <td>
                                    <select id="user_credential_code">
                                        <option value="">选择证件类型</option>
                                    </select>*</td>
                                <td>证件号码：</td>
                                <td><input type="text" id="user_credential_no"/>*</td>
                            </tr>
                            <tr>
                                <td>职称：</td>
                                <td><select id="user_title_code">
                                </select></td>
                                <td>职务：</td>
                                <td><input type="text" id="user_position"/></td>
                            </tr>
                            <tr>
                                <td>所属部门：</td>
                                <td><input type="text" id="user_department"/>*</td>
                                <td>学历：</td>
                                <td>
                                    <select id="user_qualification_code">
                                        <option value="">选择学历</option>
                                    </select></td>
                            </tr>
                            <tr>
                                <td>专业：</td>
                                <td><input type="text" id="user_profession" /></td>
                                <td>电话：</td>
                                <td><input type="text" id="user_phone" maxlength="20"/>*</td>
                            </tr>
                            <tr>
                                <td>移动电话：</td>
                                <td><input type="text" id="user_mobile" maxlength="20"/>*</td>
                                <td>住址：</td>
                                <td><input type="text" id="user_address" /></td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td valign="top" width="100%">
                        <table align="center" cellspacing="0" cellpadding="2" width="85%">
                            <tr>
                                <td align="left"><input type="button" id="SUBMIT_BUTTON" value="提交"/><span id="optRet"></span></td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>
</body>
</html>